package com.jetbrains.kmpapp

import platform.Foundation.NSBundle
import platform.UIKit.UIDevice
import kotlin.experimental.ExperimentalNativeApi

private class PlatformConfigurationProvider {

    @OptIn(ExperimentalNativeApi::class)
    val isDebug: Boolean
        get() = Platform.isDebugBinary

    val appName: String
        get() = (NSBundle.mainBundle.infoDictionary?.get("CFBundleDisplayName") as? String)
            ?: (NSBundle.mainBundle.infoDictionary?.get("CFBundleName") as? String)
            ?: "Unknown"

    val appVersion: String
        get() = (NSBundle.mainBundle.infoDictionary?.get("CFBundleShortVersionString") as? String)
            ?: "Unknown"

    val packageName: String
        get() = (NSBundle.mainBundle.bundleIdentifier ?: "UnknownBundleId")

    val platformName: String
        get() = "iOS ${UIDevice.currentDevice.systemVersion}"

    val deviceModel: String
        get() = UIDevice.currentDevice.model

}

actual val platformConfiguration: PlatformConfiguration by lazy {
    val provider = PlatformConfigurationProvider()
    PlatformConfiguration(
        isDebug = provider.isDebug,
        appName = provider.appName,
        appVersion = provider.appVersion,
        packageName = provider.platformName,
        platformName = provider.platformName,
        deviceModel = provider.deviceModel
    )
}